package com.system.demo.service;

import java.util.Calendar;
import java.util.Date;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.system.demo.dao.IConsumeLogDao;
import com.system.demo.dao.IMemberDao;
import com.system.demo.model.ConsumeLog;
import com.system.demo.model.Member;

@Service
@Transactional
public class ConsumeLogService implements IConsumeLogService {

	@Resource
	private IConsumeLogDao consumeLogDao;
	@Resource
	private IMemberDao mumberDao;
	@Override
	public void save(ConsumeLog c) {
		Member m = mumberDao.findByCardNo(c.getCardNo());
		if(m.getStatus()>0) {
			c = consumeLogDao.getOne(c.getCardNo());
			c.setOutTime(new Date());//出来时间设为刷卡时间
			consumeLogDao.save(c);//修改离开时间
			m.setStatus(0);
			
		}else {//进去
			Calendar cal = Calendar.getInstance();
			cal.setTime(new Date());
			cal.add(Calendar.MINUTE, 30);//默认离开时间是进入时间+30分
			c.setOutTime(cal.getTime());
			consumeLogDao.save(c);//添加进入日志
			m.setStatus(c.getReadRoomId());//修改会员卡状态
		}
		mumberDao.save(m);
	}

}